<?php

namespace App\Http\Requests\service;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait AbnormalRequest
{

    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'type' => 'required|integer',
            'abnormal_desc' => 'required|string',
            'file' => 'required',
            'handle_desc' => 'required|string',
        ], [
            'type.required' => '请选择类型',
            'abnormal_desc.required' => '请填写异常描述',
            'file.required' => '请上传附件',
            'handle_desc.required' => '请填写处理描述',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function admin_add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
//            'order_sn' => 'required|string',
            'type' => 'required|integer',
            'abnormal_desc' => 'required|string',
//            'file' => 'required',
//            'handle_desc' => 'required|string',
        ], [
            'order_sn.required' => '请填写入仓号',
            'type.required' => '请选择类型',
            'abnormal_desc.required' => '请填写异常描述',
//            'file.required' => '请上传附件',
//            'handle_desc.required' => '请填写处理描述',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function handle_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'mode_id' => 'required|integer',
        ], [
            'mode_id.required' => '请选择处理方式',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


    public static function problem_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'type_id' => 'required|integer|exists:t_service_problem_type,id',
            'description' => "required|string",
        ], [
            'type_id.required' => '请选择类型',
            'description' => '请填写描述'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function day_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'day' => 'required|integer',
        ], [
            'day.required' => '请填写天数',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
